package com.southpark.system.view
{
	import com.southpark.system.interfaces.managers.IToolTipManager;
	import com.southpark.system.interfaces.view.IToolTipUI;
	import com.southpark.system.view.toolTips.ToolTipTarget;
	
	import flash.events.MouseEvent;
	
	import mx.core.FlexGlobals;
	
	import spark.components.Group;
	
	
	public class AbstractToolTipUI extends Group implements IToolTipUI
	{
		
		public function AbstractToolTipUI()
		{
			addEventListener(MouseEvent.ROLL_OUT,onRollOut);
		}
		
		private var _data:Object;
		public function get data():Object
		{
			return _data;
		}
		public function set data(value:Object):void
		{
			_data = value;
		}
		
		private var _toolTipManager:IToolTipManager;
		public function set toolTipManager(value:IToolTipManager):void
		{
			_toolTipManager = value;
		}
		
		private var _toolTipTarget:ToolTipTarget;
		public function set toolTipTarget(value:ToolTipTarget):void
		{
			_toolTipTarget = value;
		}
		public function get toolTipTarget():ToolTipTarget
		{
			return _toolTipTarget;
		}
		
		
		public function isMouseTrapped():Boolean
		{
			return hitTestPoint(FlexGlobals.topLevelApplication.mouseX,FlexGlobals.topLevelApplication.mouseY,true)
		}
		
		
		private function onRollOut(event:MouseEvent):void
		{
			if (!_toolTipTarget.isMouseTrapped())
			{
				hideToolTip();
			};
		}
		
		public function hideToolTip():void
		{
			_toolTipManager.hideToolTip();
		}
		
	}
}